from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 修改密码用例：case_006---反向用例

driver = webdriver.Firefox()
driver.maximize_window()
driver.get('https://bj.5i5j.com/')
# 隐式等待
driver.implicitly_wait(5)

sleep(3)
# 点击登录
driver.find_element(By.ID, 'home-login-btn').click()
sleep(2)
# 点击密码登录
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[3]/div[2]').click()
sleep(2)
# 显示等待***输入账号
sjh = WebDriverWait(driver, 10).until(
    EC.element_to_be_clickable((By.XPATH, '//*[@id="phone1"]'))
)
# 输入账号
sjh.send_keys('15985645480')
sleep(2)
# 输入密码
driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div[4]/div[3]/input').send_keys('gW09092434')
sleep(2)
# 点击立即登录
driver.find_element(By.ID, 'login-submit').click()
sleep(3)
# 1、点击用户信息（头像）
driver.find_element(By.ID, 'toUserCenter').click()
sleep(2)
# 窗口切换
driver.switch_to.window(driver.window_handles[-1])
sleep(3)
# 2、点击设置
driver.find_element(By.XPATH, '//a[@href="/user/set"]').click()
sleep(2)
# 3、点击修改密码
exit = driver.find_element(By.CSS_SELECTOR, '#navPwd')
exit.click()
sleep(2)
# 获取元素文本
print(f"元素文本：{exit.text}")
# 获取元素尺寸
print(f"元素尺寸-宽度：{exit.size['width']}, 高度：{exit.size['height']}")
# 获取元素坐标
print(f"元素坐标-x：{exit.location['x']}, y:{exit.location['y']}")
# 4、输入旧密码
driver.find_element(By.XPATH, '//*[@id="textOldPwd"]').send_keys('gw09092434')
sleep(2)
# 5、输入新密码
driver.find_element(By.XPATH, '//*[@id="textNewPwd"]').send_keys('gw09092434')
# 6、输入确认新密码
driver.find_element(By.XPATH, '//*[@id="textNewPwdRepeat"]').send_keys('gw09092434')
# 7、点击修改
driver.find_element(By.XPATH, '/html/body/div[4]/div/div[2]/div[2]/div[2]/div[2]/ul/li[4]/a').click()

sleep(10)







